<?php
    class DB {
        private $host="localhost";
        private $user="root";
        private $pass="12345";
        private $dbres;
        private $ans;

        function __construct() {
            $this->dbres = @mysql_connect($this->host, $this->user ,$this->pass, true);
            @mysql_query("set names utf8 collate utf8_general_ci");
            if(!$this->dbres) {
                echo "Can not connect to database<br>";
                exit(1);
            }
            $this->sdb("chiefonline");
            $this->ans = array();
        }
        function __destruct() {
            if($this->dbres) {
                @mysql_close($this->dbres);
            }
        }
        public function sdb($dbname) {
            if(!(@mysql_select_db($dbname, $this->dbres))){
                echo "Can not select database\r\n";
                exit(2);
            }
        }
        public function dbq($query) {
            $this->ans[0] = @mysql_query($query, $this->dbres);
            if(!$this->ans[0]) {
                echo "Query Error\r\n";
                $file = fopen(dirname(__FILE__)."/db.errors.log", "a+");
                fputs($file, $_SERVER["PHP_SELF"]."\r\n");
                fputs($file, $query."\r\n");
                fputs($file, mysql_error($this->dbres)."\r\n\r\n");
                fclose($file);
            }
        }
        public function dbqi($index, $query) {
            $this->ans[$index] = @mysql_query($query, $this->dbres);
            if(!$this->ans[$index]) {
                echo "Query Error\r\n";
                $file = fopen(dirname(__FILE__)."/db.errors.log", "a+");
                fputs($file, $_SERVER["PHP_SELF"]."\r\n");
                fputs($file, mysql_error($this->dbres)."\r\n\r\n");
                fputs($file, $query."\r\n");
                fclose($file);
            }
        }
        public function assoc() {
            return @mysql_fetch_assoc($this->ans[0]);
        }
        public function associ($index) {
            return @mysql_fetch_assoc($this->ans[$index]);
        }
        public function row() {
            return @mysql_fetch_row($this->ans[0]);
        }
        public function rowi($index) {
            return @mysql_fetch_row($this->ans[$index]);
        }
        public function afr() {
            return @mysql_affected_rows($this->ans[0]);
        }
        public function afri($index) {
            return @mysql_affected_rows($this->ans[$index]);
        }
    }
?>